package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SquareCarousel;
import com.ruoyi.system.service.ISquareCarouselService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * animal.`square_Carousel`Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/system/carousel")
public class SquareCarouselController extends BaseController
{
    private String prefix = "system/carousel";

    @Autowired
    private ISquareCarouselService squareCarouselService;

    @RequiresPermissions("system:carousel:view")
    @GetMapping()
    public String carousel()
    {
        return prefix + "/carousel";
    }

    /**
     * 查询animal.`square_Carousel`列表
     */
    @RequiresPermissions("system:carousel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SquareCarousel squareCarousel)
    {
        startPage();
        List<SquareCarousel> list = squareCarouselService.selectSquareCarouselList(squareCarousel);
        return getDataTable(list);
    }

    /**
     * 导出animal.`square_Carousel`列表
     */
    @RequiresPermissions("system:carousel:export")
    @Log(title = "animal.`square_Carousel`", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SquareCarousel squareCarousel)
    {
        List<SquareCarousel> list = squareCarouselService.selectSquareCarouselList(squareCarousel);
        ExcelUtil<SquareCarousel> util = new ExcelUtil<SquareCarousel>(SquareCarousel.class);
        return util.exportExcel(list, "animal.`square_Carousel`数据");
    }

    /**
     * 新增animal.`square_Carousel`
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存animal.`square_Carousel`
     */
    @RequiresPermissions("system:carousel:add")
    @Log(title = "animal.`square_Carousel`", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SquareCarousel squareCarousel)
    {
        return toAjax(squareCarouselService.insertSquareCarousel(squareCarousel));
    }

    /**
     * 修改animal.`square_Carousel`
     */
    @RequiresPermissions("system:carousel:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SquareCarousel squareCarousel = squareCarouselService.selectSquareCarouselById(id);
        mmap.put("squareCarousel", squareCarousel);
        return prefix + "/edit";
    }

    /**
     * 修改保存animal.`square_Carousel`
     */
    @RequiresPermissions("system:carousel:edit")
    @Log(title = "animal.`square_Carousel`", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SquareCarousel squareCarousel)
    {
        return toAjax(squareCarouselService.updateSquareCarousel(squareCarousel));
    }

    /**
     * 删除animal.`square_Carousel`
     */
    @RequiresPermissions("system:carousel:remove")
    @Log(title = "animal.`square_Carousel`", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(squareCarouselService.deleteSquareCarouselByIds(ids));
    }
}
